define([
  'jquery',
  'routers/Router',
  'models/User',
  'models/Message',
  'collections/Collection',
  'collections/Messages',
  'collections/Notifications',
  'views/users/UserProfile',
  'views/users/ShareView',
  'views/users/inbox/InboxView',
  'views/users/inbox/InboxDetailView',
  'views/users/notifications/NotificationsView',
  'views/users/internet/InternetView',
  'views/users/takephoto/TakePhoto'
], function($, Router, User, Message, Collection, Messages, Notifications, UserProfile, ShareView, InboxView, InboxDetailView, NotificationsView, InternetView, TakePhotoView){
  var UserRouter = Router.extend({
    type: "",
    
    routes: {
      "":                               "notifications",
      "!/profile":                      "profile",
      "!/upload":                       "upload",
      "!/inbox/:id":                    "inbox",
      "!/inbox":                        "inbox",
      "!/outbox/:id":                    "outbox",
      "!/outbox":                        "outbox",
      "!/notifications":                "notifications",
      "!/internet":                     "internet",
      "!/takephoto":                    "takephoto" 
    },

    default: function() {
      this.Logger.debug("Ruta default!");
      $("#app").html("Ruta default! No implementada!");
    },
    
    profile: function() {
      this.Logger.debug("Familiar router, profile route!");
      var user = new User();
      var profile = new UserProfile({model: user});
      $("#app").html(profile.render().el);
      
      user.fetch();
    },

    upload: function() {
      this.Logger.debug("User router, upload route!");
      var user = new User();
      //user.internals.fetch();
      
      var shareView = new ShareView({el: "#app", model: user, type: this.type, messages: this.messages});
      shareView.render();
      //      $("#app").html(shareView.render().el);
    },

    inbox: function(id) {
      console.log("inbox id: " + id);
      var view;
      if(id) {
        var message = new Message({id: id, type: "inbox"});
        view = new InboxDetailView({model: message, type: "inbox"});
        $("#app").html(view.render().el);
        message.fetch();
      } else {
        var messages = new Messages([], {type: "inbox"});
        messages.pagination.setLimit(10);
        view = new InboxView({collection: messages, type: "inbox"});
        $("#app").html(view.render().el);
        messages.fetch();
      }

    },

    outbox: function(id) {
      console.log("outbox id: " + id);
      var view;
      if(id) {
        var message = new Message({id: id, type: "outbox"});
        view = new InboxDetailView({model: message, type: "outbox"});
        $("#app").html(view.render().el);
        message.fetch();
      } else {
        var messages = new Messages([], {type: "outbox"});
        messages.pagination.setLimit(10);
        view = new InboxView({collection: messages, type: "outbox"});
        $("#app").html(view.render().el);
        messages.fetch();
      }

    },

    notifications: function() {
      var notifications = new Notifications();
      notifications.pagination.setLimit(10);
      var view = new NotificationsView({collection: notifications});
      $("#app").html(view.render().el);

      notifications.fetch();
    },

    internet: function() {
      console.log("Internet route!");
      var view = new InternetView();
      $("#app").html(view.render().el);
    },

    takephoto: function() {
      var view = new TakePhotoView({messages: this.messages});
      $("#app").html(view.render().el);
    }

  });

  return UserRouter;
});